package com.chuan.thinkingjava.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileCreateTest {

	public static void main(String[] args) throws IOException {
		File file1 = new File("C:\\Users\\Administrator\\Desktop" + File.separator + "test1.txt");
		File file2 = new File("C:\\Users\\Administrator\\Desktop" + File.separator + "test2.txt");
		
		File file3 = new File("C:\\Users\\Administrator\\Desktop" + File.separator + "test3.zip");
		
		
//		FileOutputStream out = new FileOutputStream(file1);
		OutputStream out = new FileOutputStream("C:\\Users\\Administrator\\Desktop" + File.separator + "test1.txt");
		String str_test = "hello word";
		out.write(str_test.getBytes());
		
		FileInputStream in = new FileInputStream(file1);

		//一个字节一个字节的读
//		int b = -1;
//		while ((b = in.read()) != -1) {
//			OutputStream out2 = new FileOutputStream(file2);
//			System.out.println(b + "         " + (char)b);
//			out2.write((char)b);
//		}
		OutputStream out2 = new FileOutputStream(file2);
		byte[] bytes = new byte[(int)file1.length()];
		in.read(bytes);
		out2.write(bytes);
		
		
		OutputStream out3 = new FileOutputStream("C:\\Users\\Administrator\\Desktop" + File.separator + "test4.txt");
		
		out3.write("hello word".getBytes());
		InputStream in4 = new FileInputStream("C:\\Users\\Administrator\\Desktop" + File.separator + "test4.txt");
		
		File file5 = new File("C:\\Users\\Administrator\\Desktop" + File.separator + "test5.txt");
		OutputStream out5 = new FileOutputStream(file5);
		
		byte[] bytess = new byte[(int) new File("C:\\Users\\Administrator\\Desktop" + File.separator + "test4.txt").length()];
		in4.read(bytess);
		out5.write(bytess);
//		FileOutputStream out1 = new FileOutputStream(file2);
//		file2.renameTo(file1);
		/*try {
			FileOutputStream out = new FileOutputStream(file1);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
//		
//		try {
//			file2.createNewFile();
//			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file3));
//			out.putNextEntry(new ZipEntry(file2.getName()));
//			FileInputStream in = new FileInputStream(file2);
//			IOUtils.copy(in, out);
//			out.closeEntry();
//			System.out.println(file3.exists());
//		} catch (IOException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		
//		try {
//			file1.createNewFile();
//			file1.renameTo(file2);
//			System.out.println(file1.exists());
//			System.out.println(file2.exists());
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
}
